package com.bm.specialvehiclefordispatcher.adapter;

import java.util.List;

import com.bm.specialvehiclefordispatcher.R;
import com.bm.specialvehiclefordispatcher.bean.Station;
import com.bm.specialvehiclefordispatcher.utils.ViewHolder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MySitesAdapter extends BaseAdapter {
	List<Station> stations;
	Context context;

	public MySitesAdapter(Context context, List<Station> stations) {
		this.context = context;
		this.stations = stations;
	}

	@Override
	public int getCount() {
		return stations == null ? 0 : stations.size();
	}

	@Override
	public Object getItem(int position) {
		return stations.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_mysites, null);
		}
		ImageView imageView = ViewHolder.get(convertView, R.id.item_mysites_im);
		TextView textView = ViewHolder.get(convertView, R.id.item_mysites_tx);

		if (stations.get(position).isCheck == true) {
			imageView.setBackgroundResource(R.drawable.register_agree);
		} else {
			imageView.setBackgroundResource(R.drawable.register_disagree);
		}
		textView.setText(stations.get(position).name);

		return convertView;
	}

}
